//
//  WBHomeTableViewController.m
//  微博项目
//
//  Created by ma c on 16/8/13.
//  Copyright (c) 2016年 beijing. All rights reserved.
//

#import "WBHomeTableViewController.h"
#import "UIBarButtonItem+WBExtension.h"
#import "UIView+WBExtension.h"
#import "WBDropdownMenu.h"
#import "WBTitleMenuViewController.h"

@interface WBHomeTableViewController ()<WBDropdownMenuDelegate>

@end

@implementation WBHomeTableViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    //设置导航栏上的内容
    self.navigationItem.leftBarButtonItem = [UIBarButtonItem itemWithTarget:self action:@selector(friendSearch) image:@"navigationbar_friendsearch" hightImage:@"navigationbar_friendsearch_highlighted"];
    self.navigationItem.rightBarButtonItem = [UIBarButtonItem itemWithTarget:self action:@selector(pop) image:@"navigationbar_pop" hightImage:@"navigationbar_pop_highlighted"];
    //设置中间的标题按钮
    UIButton * titleButton = [[UIButton alloc]init];
    titleButton.width = 150;
    titleButton.height = 30;
    [titleButton setTitle:@"首页" forState:UIControlStateNormal];
    [titleButton setTitleColor:[UIColor blackColor] forState:UIControlStateNormal];
    titleButton.titleLabel.font = [UIFont systemFontOfSize:17];
    
    [titleButton setImage:[UIImage imageNamed:@"navigationbar_arrow_down"] forState:UIControlStateNormal];
    [titleButton setImage:[UIImage imageNamed:@"navigationbar_arrow_up"] forState:UIControlStateSelected];
    titleButton.imageEdgeInsets = UIEdgeInsetsMake(0, 70, 0, 0);
    titleButton.titleEdgeInsets = UIEdgeInsetsMake(0, 0, 0, 40);
    [titleButton addTarget:self action:@selector(titleClick:) forControlEvents:UIControlEventTouchUpInside];
    self.navigationItem.titleView = titleButton;
}

//点击创建下拉菜单
- (void)titleClick:(UIButton *)titleButton{
    WBDropdownMenu * menu = [[WBDropdownMenu alloc]init];
    menu.delegate = self;
    WBTitleMenuViewController * vc = [[WBTitleMenuViewController alloc]init];
    vc.view.height = 150;
    vc.view.width = 150;
    menu.contentController = vc;
    [menu showFrom:titleButton];
    
}
#pragma mark - HWDropdownMenuDelegate
/**
 *  下拉菜单被销毁了
 */
- (void)dropdownMenuDidDismiss:(WBDropdownMenu *)menu
{
    UIButton *titleButton = (UIButton *)self.navigationItem.titleView;
    // 让箭头向下
    titleButton.selected = NO;
}

/**
 *  下拉菜单显示了
 */
- (void)dropdownMenuDidShow:(WBDropdownMenu *)menu
{
    UIButton *titleButton = (UIButton *)self.navigationItem.titleView;
    // 让箭头向上
    titleButton.selected = YES;
}




- (void)friendSearch{
    NSLog(@"friendSearch");
}

- (void)pop{
    NSLog(@"pop");
}
















#pragma mark - Table view data source

- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView {
#warning Potentially incomplete method implementation.
    // Return the number of sections.
    return 0;
}

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
#warning Incomplete method implementation.
    // Return the number of rows in the section.
    return 0;
}

@end
